package com.digitalchina.lxnsy.viewholder;

import androidx.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.CollectVO;
import com.digitalchina.lxnsy.interfaces.ICallBackPos;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/8/6 11:10
 * 修改备注：
 * ================================================
 */

public class CollectHolder extends BaseViewHolder<CollectVO> {

    private SimpleDraweeView ivPicture;
    private TextView tvTitle;
    private TextView tvTime;
    private TextView tvCancel;
    private ICallBackPos iCallBackPos;
    private  String type;


    public CollectHolder(ViewGroup parent,String type, ICallBackPos iCallBackPos) {
        super(parent, R.layout.item_collect);
        ivPicture = $(R.id.sdv_images);
        tvTitle = $(R.id.tv_title);
        tvTime = $(R.id.tv_time);
        tvCancel = $(R.id.tv_cancel);
       this.type=type;

        this.iCallBackPos = iCallBackPos;
    }

    @Override
    public void setData(CollectVO data) {
        super.setData(data);

        if("0".equals(type)){
            FrescoUtil.showImageSmall(data.getImgPath(), ivPicture);
            tvTitle.setText(data.getName() + "");
            tvTime.setText(data.getCreateTime() + "");


        }else  if("2".equals(type)){
           String[] arr= data.getImgPath().split(",");

            FrescoUtil.showImageSmall(arr[0], ivPicture);
            tvTitle.setText(data.getActivityName() + "");
            tvTime.setText(data.getAddress() + "");


        }  else if("3".equals(type)){
            FrescoUtil.showImageSmall(data.getImgUrl(), ivPicture);

            tvTitle.setText(data.getTitle() + "");
            tvTime.setText(data.getCreateTime() + "");

        }
        else{
            FrescoUtil.showImageSmall(data.getImg(), ivPicture);

            tvTitle.setText(data.getName() + "");
            tvTime.setText(data.getPageViewNums() + "次播放");

        }




        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(getContext())
                        .title("提示")
                        .content("确定要取消收藏这条信息？")
                        .positiveText("确定")
                        .negativeText("取消")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                iCallBackPos.clickOk(getAdapterPosition());
                            }
                        })
                        .show();
            }
        });
    }

}
